package com.yserp.project.erp.store.outstorelog.controller;

import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.common.utils.text.Convert;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.store.outstorelog.domain.StockOutLog;
import com.yserp.project.erp.store.outstorelog.service.IStockOutLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

/**
 * 出库日志Controller
 * 
 * @author yserp
 * @date 2022-07-14
 */
@Controller
@RequestMapping("/store/outstorelog")
public class StockOutLogController extends BaseController
{
    private String prefix = "erp/store/outstorelog";

    @Autowired
    private IStockOutLogService stockOutLogService;

    @RequiresPermissions("store:outstorelog:view")
    @GetMapping()
    public String outstorelog()
    {
        return prefix + "/outstorelog";
    }

    /**
     * 查询出库日志列表
     */
    @RequiresPermissions("store:outstorelog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StockOutLog stockOutLog)
    {
        startPage();
        List<StockOutLog> list = stockOutLogService.selectStockOutLogList(stockOutLog);
        return getDataTable(list);
    }

    /**
     * 导出出库日志列表
     */
    @RequiresPermissions("store:outstorelog:export")
    @Log(title = "出库日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StockOutLog stockOutLog)
    {
        List<StockOutLog> list = stockOutLogService.selectStockOutLogList(stockOutLog);
        ExcelUtil<StockOutLog> util = new ExcelUtil<StockOutLog>(StockOutLog.class);
        return util.exportExcel(list, "出库日志数据");
    }

    /**
     * 新增出库日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出库日志
     */
    @RequiresPermissions("store:outstorelog:add")
    @Log(title = "出库日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StockOutLog stockOutLog)
    {
        return toAjax(stockOutLogService.save(stockOutLog));
    }

    /**
     * 修改出库日志
     */
    @RequiresPermissions("store:outstorelog:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StockOutLog stockOutLog = stockOutLogService.getById(id);
        mmap.put("stockOutLog", stockOutLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存出库日志
     */
    @RequiresPermissions("store:outstorelog:edit")
    @Log(title = "出库日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StockOutLog stockOutLog)
    {
        return toAjax(stockOutLogService.updateById(stockOutLog));
    }

    /**
     * 删除出库日志
     */
    @RequiresPermissions("store:outstorelog:remove")
    @Log(title = "出库日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stockOutLogService.removeByIds(Arrays.asList(Convert.toLongArray(ids))));
    }
}
